package com.oceansoft.mobile.econsole.modules.api.controller;

import com.oceansoft.mobile.econsole.common.util.StringUtils;
import com.oceansoft.mobile.econsole.modules.api.service.IQueryService;
import com.oceansoft.mobile.econsole.modules.base.entity.Result;
import com.oceansoft.mobile.econsole.modules.check.entity.IdNumCheck;
import com.oceansoft.mobile.econsole.modules.check.entity.VehicleCheck;
import com.oceansoft.mobile.econsole.modules.check.service.ICheckService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import static org.springframework.web.bind.annotation.RequestMethod.GET;
import static org.springframework.web.bind.annotation.RequestMethod.POST;

/**
 * 一键核查接口
 *
 * @author huqp
 * @version 2016-02-02
 */
@RestController
@RequestMapping("api/check")
public class ApiCheckController {

    @Resource
    private ICheckService checkService;

    @Resource
    private IQueryService queryService;

    /**
     * 身份证号核查
     *
     * @param idNumCheck 待查询身份证号
     * @return Result
     */
    /*@RequestMapping(value = "idNum", method = POST)
    public Result idnumCheck(@RequestBody IdNumCheck idNumCheck) {
        if (StringUtils.isBlank(idNumCheck.getIdNum())) {
            return new Result(Result.FAILURE,"请输入查询身份证号!");
        }
        if(StringUtils.isBlank(idNumCheck.getMemberId())){
            return new Result(Result.FAILURE,"请输入查询用户ID");
        }

        return checkService.saveIdNumCheck(idNumCheck);
    }*/

    // 20160412注掉，数据库in表出现010101只有guid和sfzhm的数据
/*    @RequestMapping(value = "idNum", method = POST)
    public Result idnumCheck(HttpServletRequest request) {

        return queryService.queryIdNumCheck(request);
    }*/

    /**
     * 车牌号核查
     *
     * @param vehicleCheck 待查询车牌号
     * @return Result
     */
    /*@RequestMapping(value = "vehicleNum", method = POST)
    public Result duplicationNameQuery(@RequestBody VehicleCheck vehicleCheck) {
        if (StringUtils.isBlank(vehicleCheck.getVehicleNum())) {
            return new Result(Result.FAILURE,"请输入查询车牌号!");
        }

        if (StringUtils.isBlank(vehicleCheck.getMemberId())) {
            return new Result(Result.FAILURE,"请输入查询用户ID");
        }

        return checkService.saveVehicleCheck(vehicleCheck);
    }*/
    @RequestMapping(value = "vehicleNum", method = POST)
    public Result vehicleNumCheck(HttpServletRequest request) {

        return queryService.queryVehicleCheck(request);
    }

    /**
     * 供外网DCN监听程序使用 推送消息给手机端
     *
     * @return
     */
    @RequestMapping(value = "dcn/idnum/{guid}", method = GET)
    public Result dcnIdNumCheck(@PathVariable("guid") String guid) {
        if(StringUtils.isBlank(guid)){
            return new Result(Result.FAILURE,"请输入guid");
        }

        return checkService.pushIdNumCheck(guid);
    }

    /**
     * 供外网DCN监听程序使用 推送消息给手机端
     *
     * @return
     */
    @RequestMapping(value = "dcn/vehicleNum/{guid}", method = GET)
    public Result dcnVehicleNumCheck(@PathVariable("guid") String guid) {
        if(StringUtils.isBlank(guid)){
            return new Result(Result.FAILURE,"请输入guid");
        }

        return checkService.pushVehicleNumCheck(guid);
    }
}
